package com.dk.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.dk.model.Work;
import com.dk.model.Workstations;
import com.dk.mapper.WorkstationsMapper;
import com.dk.service.WorkstationsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dk.vo.WorkstationsVO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author wbh
 * @since 2023-03-21
 */
@Service
public class WorkstationsServiceImpl extends ServiceImpl<WorkstationsMapper, Workstations> implements WorkstationsService {
    @Resource
    private WorkstationsMapper workstationsMapper;

    @Override
    public List<WorkstationsVO> getInfoList(WorkstationsVO workstationsVO) {
        /*工作站编码,工作站名称,所在车间名称,所属工序*/
        LambdaQueryWrapper<Workstations> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(StringUtils.isNotBlank(workstationsVO.getWorkstationId()), Workstations::getWorkstationId, workstationsVO.getWorkstationId());
        wrapper.like(StringUtils.isNotBlank(workstationsVO.getWorkstationName()), Workstations::getWorkstationName, workstationsVO.getWorkstationName());
        wrapper.eq(StringUtils.isNotBlank(workstationsVO.getShopId()), Workstations::getShopId, workstationsVO.getShopId());
        wrapper.eq(StringUtils.isNotBlank(workstationsVO.getProcedureId()), Workstations::getProcedureId, workstationsVO.getProcedureId());
        List<WorkstationsVO> collect = workstationsMapper.selectList(wrapper).stream().map(workstations -> {
            WorkstationsVO vo = new WorkstationsVO();
            BeanUtils.copyProperties(workstations, vo);
            return vo;
        }).collect(Collectors.toList());
        return collect;
    }

    @Override
    public void insertInfoWorkstations(WorkstationsVO workstationsVO) {
        Workstations workstations = new Workstations();
        BeanUtils.copyProperties(workstationsVO, workstations);
        workstationsMapper.insert(workstations);
    }

    @Override
    public WorkstationsVO getInfoWorkstationsById(String workstationId) {
        Workstations workstations = workstationsMapper.selectById(workstationId);
        WorkstationsVO workstationsVO = new WorkstationsVO();
        BeanUtils.copyProperties(workstations, workstationsVO);
        return workstationsVO;
    }

    @Override
    public void updateInfoWorkstationsById(WorkstationsVO workstationsVO) {
        Workstations workstations = new Workstations();
        BeanUtils.copyProperties(workstationsVO, workstations);
        workstationsMapper.updateById(workstations);
    }

    @Override
    public void deleteInfoWorkstationsById(String workstationId) {
        workstationsMapper.deleteById(workstationId);
    }

    @Override
    public Workstations selectInfoWorkstationsById(String workstationsId) {
        Workstations workstations = workstationsMapper.selectById(workstationsId);
        return workstations;
    }
}
